#include "wdg.h"
#include "led.h"

/*void IWDG_Init(u8 prer,u16 rlr) 
{	
 	IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);  //??????IWDG_PR?IWDG_RLR????
	
	IWDG_SetPrescaler(prer);  //??IWDG????:??IWDG?????64
	
	IWDG_SetReload(rlr);  //??IWDG????
	
	IWDG_ReloadCounter();  //??IWDG???????????IWDG???
	
	IWDG_Enable();  //??IWDG
}
//??????
*/
void IWDG_Feed(void)
{   
 	IWDG_ReloadCounter();	//?????									   
}


//??WWDG???????,?????. 
u8 WWDG_CNT=0x7f; 

void WWDG_Init(u8 tr,u8 wr,u32 fprer)
{ 
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);  //   WWDG????

	WWDG_CNT=tr&WWDG_CNT;   //???WWDG_CNT.   
	WWDG_SetPrescaler(fprer);////??IWDG????

	WWDG_SetWindowValue(wr);//?????

	WWDG_Enable(WWDG_CNT);	 //????? ,	?? counter .                  

	WWDG_ClearFlag();//??????????? 

	WWDG_NVIC_Init();//???????? NVIC

	WWDG_EnableIT(); //?????????
} 
//???WWDG?????
void WWDG_Set_Counter(u8 cnt)
{
    WWDG_Enable(cnt);//????? ,	?? counter .	 
}
//???????????
void WWDG_NVIC_Init()
{
	NVIC_InitTypeDef NVIC_InitStructure;
	NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;    //WWDG??
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;   //??2,????3,?2	
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;	 //??2,????3,?2	
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);//NVIC???
}

void WWDG_IRQHandler(void)
	{

	WWDG_SetCounter(WWDG_CNT);	  //??????,??????????

	WWDG_ClearFlag();	  //???????????

	LED1=!LED1;		 //LED????
	}


